/*
 * BlockBitMapTest.cpp
 *
 */

#include "BlockBitMapTest.h"
#include "../persistence/blockManagment/BlockBitMap.h"
#include "../utils/Utils.h"
#include <iostream>

BlockBitMapTest::BlockBitMapTest() {}

BlockBitMapTest::~BlockBitMapTest() {}

void BlockBitMapTest::getFreeBlock() const {
	std::cout << "obtencion de bloques libres" << std::endl;
	BlockBitMap bitmap;
	BigInt index = bitmap.getFreeBlock();
	std::cout << bitmap.toString() << " obtenido el bloque: " << Utils::toString(index) << std::endl;
	bitmap.take(index);
	std::cout << "tomado el bloque " << Utils::toString(index) << std::endl;
	index = bitmap.getFreeBlock();
	std::cout << bitmap.toString() << " obtenido el bloque: " << Utils::toString(index) << std::endl;
	bitmap.take(index);
	std::cout << "tomado el bloque " << Utils::toString(index) << std::endl;
	index = bitmap.getFreeBlock();
	std::cout << bitmap.toString() << " obtenido el bloque: " << Utils::toString(index) << std::endl;
	bitmap.take(index);
	std::cout << "tomado el bloque " << Utils::toString(index) << std::endl;
	bitmap.free(1);
	std::cout << "liberado el bloque 1" << std::endl;
	index = bitmap.getFreeBlock();
	std::cout << bitmap.toString() << " obtenido el bloque: " << Utils::toString(index) << std::endl;
}

void BlockBitMapTest::persistence() const {
	std::cout << "Guardar y cargar el bitmap" << std::endl;
	BlockBitMap bitmap;
	bitmap.create("hola.dat");
	BigInt index = bitmap.getFreeBlock();
	bitmap.take(index);
	index = bitmap.getFreeBlock();
	bitmap.take(index);
	index = bitmap.getFreeBlock();
	bitmap.take(index);
	bitmap.free(1);
	std::cout << "guardando el bitmap: " << bitmap.toString() << std::endl;
	bitmap.save();
	bitmap.load();
	std::cout << "levantado el bitamp: " << bitmap.toString() << std::endl;
}
